package com.cxg.allsys.expertsys.service.impl;




import com.cxg.allsys.expertsys.mapper.ExpertsysMapper;
import com.cxg.allsys.expertsys.pojo.Article;
import com.cxg.allsys.expertsys.pojo.Comment;
import com.cxg.allsys.expertsys.pojo.TExpert;
import com.cxg.allsys.expertsys.service.IExpertsysService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Slf4j
@Service
public class ExpertsysSeviceImpl implements IExpertsysService
{
    @Autowired(required = false)
    private ExpertsysMapper expertsysMapper;

    //登录
    @Override
    public TExpert expertsysLogin(String phone , String password) {
        TExpert texpert = expertsysMapper.selectLogin(phone,password);
        if(texpert != null) {
            return texpert;
        }else {
            return null;
        }
    }

    //根据ID查询专家
    @Override
    public TExpert expertsysID(Integer expertid) {
        return expertsysMapper.selectID(expertid);

    }

    //重置密码
    @Override
    public boolean resetpassword(Integer expertid, String password, String newpassword) {
        return expertsysMapper.resetpassword(expertid,password,newpassword);
    }

    //文章显示
    @Override
    public List<Article> selectdata() {
        System.out.println(expertsysMapper.selectdata());
        return expertsysMapper.selectdata();
    }
    //根据ID查询文章内容
    @Override
    public Article neirongdata(Integer id) {
        return expertsysMapper.neirong(id);
    }

    //添加评论
    @Override
    public String addpinglun(Integer article_id, Integer expert_id, String c_content, String is_recommend) {
        Comment comment = new Comment();
        comment.setArticle_id(article_id);
        comment.setExpert_id(expert_id);
        comment.setC_content(c_content);
        comment.setCreate_date(new Date());
        comment.setIs_recommend(is_recommend);
        if(expertsysMapper.addpinglun(comment)){
            return "评论成功";
        }else {
            return "系统繁忙";
        }

    }
//根据专家ID查询评论
    @Override
    public List<Comment> selectComment(Integer expert_id) {
        return expertsysMapper.selectComment(expert_id);
    }
//删除评论
    @Override
    public String delectCommernt(Integer c_id) {
        System.out.println( c_id   + "+++++++++++++++");
        if(expertsysMapper.delectpinglun(c_id)){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }
}
